<template>
	<view class="container">
		<template v-if="show">
			<view class="use-box">
				<view class="use-item" v-for="(item, index) in dataList" key="index">
					<view class="time v-center">{{ item.createTime }}</view>
					<view class="space-between cont">
						<view class="left">
							<view class="text">使用门店：{{ item.shopName }}</view>
							<view class="text">使用方式：{{ item.useType == 1 ? "二维码" : "会员码" }}</view>
							<view class="text">订单号：{{ item.code }}</view>
						</view>
						<view class="right center" @click="copyText(item.code)">
							<image src="https://fuqiaohui.oss-cn-chengdu.aliyuncs.com/user/copy.png" class="copy-img"></image>
						</view>
					</view>
				</view>
				<view class="no-data" v-if="!dataList.length">暂无数据</view>
				<view class="no-data" v-if="noMore">没有更多了</view>
			</view>
		</template>
	</view>
</template>

<script>
	import {
		getUseList
	} from "../../api/active"
	import {
		getTimeBytimeStamp
	} from "../../utils/plug.js"
	export default {
		data() {
			return {
				size: 10,
				show: false,
				current: 1,
				noMore: false,
				dataList: []
			}
		},
		onLoad() {
			this.getData()
		},
		methods: {
			getData() {
				uni.showLoading({
					title: "加载中..."
				})
				getUseList({
						userId: uni.getStorageSync("userId"),
						size: this.size,
						current: this.current
					})
					.then(res => {
						this.show = true
						uni.hideLoading()
						uni.stopPullDownRefresh()
						if (this.current == 1) {
							this.dataList = res.data.records
						} else {
							this.dataList = [...this.dataList, ...res.data.records]
						}
						if (res.data.records.length) {
							this.dataList.forEach(item => {
								item.createTime = getTimeBytimeStamp(item.createTime)
							})
							if (res.data.total > this.current * this.size) {
								this.noMore = false
								this.current++
							} else {
								this.noMore = true
							}
						}
					})
					.catch(() => {
						uni.hideLoading()
						uni.stopPullDownRefresh()
					})
			},
			copyText(text) {
				uni.setClipboardData({
					data: text.toString(),
					success() {
						uni.showToast({
							title: "复制成功",
							icon: "none",
							duration: 2000
						})
					}
				})
			}
		},
		onPullDownRefresh() {
			this.current = 1
			this.noMore = false
			this.getData()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (!this.noMore) {
				this.getData()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.no-data {
		font-weight: 500;
		font-size: 26rpx;
		color: #999999;
		text-align: center;
		padding-top: 20rpx;
	}

	.container {
		width: 100vw;
		background: #f5f5f5;
		padding-bottom: 20rpx;
	}

	.use-box {
		display: flex;
		flex-direction: column;
	}

	.use-item {
		width: 100%;
		height: 288rpx;
		background: #ffffff;
		padding: 0 24rpx;
		margin-top: 20rpx;

		.time {
			height: 80rpx;
			font-weight: 800;
			font-size: 30rpx;
			color: #333333;
			border-bottom: 1px solid #f1f1f1;
		}
	}

	.cont {
		margin-top: 30rpx;
		align-items: flex-end;

		.left {
			display: flex;
			flex-direction: column;
			gap: 20rpx;

			.text {
				font-weight: 500;
				font-size: 28rpx;
				color: #666666;
			}
		}

		.right {
			.copy-img {
				width: 31rpx;
				height: 31rpx;
			}
		}
	}
</style>